<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>秒杀管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/index.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/index.js"></script>
    </head>
	<style type="text/css">
		.kuangao{
			width: 200px;
		}
		.juzhong{
			margin-left: auto;
			margin-right: auto;
			width: 700px;
			height:190px;
		}
		.biao_left{
			float: left;
		}
		.biao_riht{
			float: right;
		}
		
	</style>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a >首页</a>
            <a >演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="juzhong">
                               <form role="form">
                               	<div class="form-group">
                               		<table class="biao_left">
										
                               		<td><label for="username">秒杀开启时间:</label></td>
                               		<td><input type="datetime-local" id="openingtime" value="" class="kuangao"/></td></tr>
                               		<tr><td></td><td>&nbsp;</td></tr>
                               		<tr> <td><label for="username">秒杀结束时间:</label></td>
                               		<td><input type="datetime-local" id="endtime" value="" class="kuangao"/></td></tr>
                               		<tr><td></td><td>&nbsp;</td></tr>
                               
                               	   <td>
								     <button class="layui-btn" onclick="establish()"><i class="layui-icon"></i>添加时间段</button>
								     <!--<input type="button" onclick="establish()"  value="添加时间段" class="layui-btn"/>-->
								   </td></tr>
                                  </table>
                               	</div>
                               </form>
							   
							   <form role="form">
							   	<div class="form-group">
							   		<table class="biao_riht">
										<td><label for="username">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;秒杀时间:</label></td>
										<td><select id="fansj" class="kuangao"></select></td></tr>
										<tr><td></td><td>&nbsp;</td></tr>
									
							   	   <tr><td><label for="username">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;秒杀价格:</label></td>
							   	    <td><input type="text" id="spikeprice" class="kuangao"></td></tr>
							   		<tr><td></td><td>&nbsp;</td></tr>
									
									
							   	   <tr> <td> <label for="username">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;商品编号:</label></td>
							   	   <td> <input type="text" id="goodsid" class="kuangao" placeholder="要添加的商品编号"></tr>
							   	   
							   	    <tr><td></td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
							          <tr><td></td>
							   	   <td><!--<button class="layui-btn" onclick="shangpintianjia()"><i class="layui-icon"></i>添加</button>-->
								     <input type="button" onclick="shangpintianjia()"  value="添加商品" class="layui-btn"/>
							   	   	
							   	   </td></tr>
							      </table>
							   	</div>
							   </form>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  <th>商品ID</th>
                                  <th>商品名</th>                    
                                  <th>商品描述</th>   
                                  <th>商品价格</th> 
                              </thead>
                              <tbody id="table">
                              </tbody>
                            </table>
                        </div>
                      
                    </div>
                </div>
            </div>
        </div> 
    </body>
   <script src="js/jquery.js"></script>

<script>
chagoods() 
function chagoods () {
	$.ajax({
		xhrFields:{withCredentials: true},
		method:"post",
		url:"http://localhost:16111/activity/chagoods",
		dataType:"json",
		success:function(date){
				str=""
				for(i in date){
					
					str+="<tr>"+
						"<td >" + date[i].id+"</td>"+
						"<td >" + date[i].commodity_name + "</td>" +  
						"<td >" + date[i].commodity_description + "</td>" +  
						"<td >" + date[i].commodity_price + "</td>" +  
						"</tr>";
				}
				document.getElementById("table").innerHTML=str;
				}
		});
}

chaxzsj ()
function chaxzsj () {
	$.ajax({
		xhrFields:{withCredentials: true},
		method:"post",
		url:"http://localhost:16111/activity/huoqusj",
		dataType:"json",
		success:function(date){
				ssr=""
				for(i in date){
					ssr+="<option>"+ date[i].openingtime+"</option>"
				}
				document.getElementById("fansj").innerHTML="<option>选择秒杀时间段</option>"+ssr;
				}
		});
}


	function establish(){
		var openingtime =document.getElementById("openingtime").value;
		var endtime =document.getElementById("endtime").value;
		var kasj=new Date(openingtime)
		var jssj=new Date(endtime)
		var kasj1=kasj.getHours()+2;
		 if(kasj1==24){
		 	kasj1=0;
		 }else if(kasj1==25){
		 	kasj1=1;
		 }
		if(kasj1==jssj.getHours()){
				$.ajax({
		xhrFields:{withCredentials: true},
		method:"post",
		url:"http://localhost:16111/activity/tjsj",
		dataType:"json",
		data:{openingtime:openingtime,
			  endtime:endtime},
		success:function(data){
					if(data==true){
						alert("添加时间成功");
					}else{
						alert("添加时间失败");
						
					}
				}
			});
		}else{
			alert("时间段选择错误 两个时间段间隔不能超过2小时")
		}
		}
	
	function shangpintianjia(){
		var kssj =document.getElementById("fansj").value;
		var spikeprice =document.getElementById("spikeprice").value;
		var goodsid =document.getElementById("goodsid").value;
	$.ajax({
		url:"http://localhost:16111/activity/shangpintianjia",
		xhrFields:{withCredentials: true},
		method:"post",
		dataType:"json",
		data:{openingtime:kssj,spikeprice:spikeprice,goodsid:goodsid},
		success:function(data){
					if(data==true){
						alert("添加成功");
					}else{
						alert("添加失败");
					}
				}
			});
		}

	</script>
    
</html>